package com.hust.bridgecheck.controller.ReportManagement;

import com.hust.bridgecheck.entity.DailySensorData;
import com.hust.bridgecheck.entity.Domain;
import com.hust.bridgecheck.service.Settings.NotifyService;
import com.hust.bridgecheck.service.UserManagement.DomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("report")
public class ReportPageController {
    //增加一些报表的管理
    @Autowired
    NotifyService notifyService;

    @Autowired
    DomainService domainService;

    @GetMapping("/manager")
    public String Manager(Model model){
        //默认获取当前时
        Date currentime = new Date();
        Calendar now5 = Calendar.getInstance();
        now5.setTime(currentime);
        int currentYear = now5.get(Calendar.YEAR);
        int nextYear = currentYear + 1;
        String Startime = currentYear + "-1-1";
        String Endtime = nextYear + "-1-1";
        List<DailySensorData> ds_lists = notifyService.getAllReport(0,Startime,Endtime);
        Set<String> reportime = new HashSet<String>();
        for(int i=0; i < ds_lists.size();i++)
        {
            reportime.add(ds_lists.get(i).getReportDate());
        }
        List<Domain> d_lists = domainService.getAllDomain();
        model.addAttribute("d_lists",d_lists);
        model.addAttribute("rt_set",reportime);
        return "baobiao";
    }

    @PostMapping("/addSpecialReport")
    public String  addSpecial(DailySensorData dailySensorData){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String Current = df.format(new Date());
        dailySensorData.setDataFlag(1);//表示用户信息
        dailySensorData.setReportDate(Current);
        notifyService.addSensorData(dailySensorData);
        return "redirect:/report/manager";
    }
}
